package com.vhall.component.controller.rbac.adm;

import com.vhall.component.entity.rbac.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.enums.OperateTypeEnum;
import com.vhall.component.service.annotation.OperateLog;
import com.vhall.component.service.rbac.RbacActionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

import java.util.List;


/**
 * @author dalong
 * @date 2021-05-12 20:55
 */
@Api(tags = "RbacAdminActionController", value = "admin权限")
@Slf4j
@VhallComponent
@Tag(name = "操作列表-管理端")
public class RbacAdminActionController implements RbacAdminActionFacade {

    @Autowired
    private RbacActionService actionService;


    @TokenAuth("sys:action:add")
    @ApiOperation("操作-添加")
    @Override
    @OperateLog(type = OperateTypeEnum.CREATE, name = "添加")
    public ActionsVO add(@Validated ActionAddReqVO reqVO) {
        return actionService.add(reqVO);
    }

    @TokenAuth("sys:action:del")
    @ApiOperation("操作-删除")
    @Override
    @OperateLog(type = OperateTypeEnum.DELETE, name = "删除")
    public Boolean delete(@Validated ActionDeleteReqVO reqVO) {
        return actionService.batchDelete(reqVO);
    }

    @ApiOperation("操作列表")
    @Override
    @TokenAuth("sys:action:list")
    public List<ActionsRspVO> list(@Validated ActionListReqVO reqVO) {
        ActionListRspVO list = actionService.getList(reqVO);
        return list.getData();
    }

    @Override
    @TokenAuth("sys:action:edit")
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "编辑")
    public Boolean edit(ActionEditReqVO reqVO) {
        return actionService.update(reqVO);
    }

    @TokenAuth("sys:action:edit")
    @Override
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "编辑")
    public Boolean update(ActionEditReqVO reqVO) {
        return actionService.update(reqVO);
    }

    @TokenAuth("sys:action:add")
    @Override
    @OperateLog(type = OperateTypeEnum.CREATE, name = "增加操作子节点")
    public ActionsVO addActions(ActionAddChildReqVO reqVO) {
        ActionAddReqVO vo = new ActionAddReqVO();
        vo.setPid(Integer.parseInt(reqVO.getPid()));
        vo.setActionName(reqVO.getActionName());
        vo.setActionTag(reqVO.getActionTag());
        vo.setDesc(reqVO.getDesc());
        return actionService.add(vo);
    }

    @TokenAuth("sys:action:edit")
    @Override
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "更新状态")
    public Boolean changeStatus(ActionChangeStatusReqVO reqVO) {
        ActionEditReqVO vo = new ActionEditReqVO();
        vo.setActionId(reqVO.getActionId());
        vo.setStatus(reqVO.getStatus());
        return actionService.updateStatus(vo);
    }
}
